<?php

/**
 * 点评管理
 */
class MessageAction extends globalAction {
    private $messageDao, $myInn;
    
    public function _initialize() {
		parent::_initialize();
        parent::_loginRequire();
        $this->messageDao = D('InnMessage');
        
        $innDao = D('Inn');
        $field = array(
            $innDao->_map['id'] => 'id',
            $innDao->_map['name'] => 'name'
        );
        $myInnList = $innDao
            ->field($field)
            ->where(array(
                $innDao->_map['menuId'] => 585,
                $innDao->_map['uid'] => __USERID__
            ))
            ->select();
        if(!empty($myInnList)) {
            $this->myInn = makearray($myInnList, 'id', 'name');
            $this->assign('myInn', $this->myInn);
        }
	}
    
    public function index() {

        $conditions[$this->messageDao->_map['menu_id']] = 608;
        $conditions[$this->messageDao->_map['inn_id']] = array('in',array_keys($this->myInn));
        
        $messageList = $this->messageDao
            ->field($this->messageDao->_map_flip)
            ->where($conditions)
            ->order(array($this->messageDao->_map['add_time']=>'desc'))
            ->select();
        $this->assign('messageList', $messageList);

        $this->display();
    }
    
    public function batch() {
        $BatKey = (array)$_POST['BatKey'];
        $BatMethod = $_POST['BatMethod'];
        
        $conditions[$this->messageDao->_map['msg_id']] = array('in',$BatKey);
        $conditions[$this->messageDao->_map['menu_id']] = 608;
        $conditions[$this->messageDao->_map['inn_id']] = array('in',array_keys($this->myInn));
        
        switch($BatMethod) {
            case 'show':
                $this->messageDao
                    ->where($conditions)
                    ->setField($this->messageDao->_map['display'],'1212');
                break;
            case 'hide':
                $this->messageDao
                    ->where($conditions)
                    ->setField($this->messageDao->_map['display'],'1213');
                break;
            case 'delete':
                $this->messageDao
                    ->where($conditions)
                    ->delete();
                break;
            default:
                parent::_message('error', '未知操作');
        }
        redirect(C('TMPL_PARSE_STRING.__KZURL__').'/message/index');
    }
}